
package com.feib.soeasy.dao;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.feib.soeasy.model.FormatDefinition;
import com.feib.soeasy.model.Group;
import com.feib.soeasy.model.Payment;
import com.feib.soeasy.model.UploadFile;
import com.feib.soeasy.model.WriteOffPayment;
import com.feib.soeasy.pagination.PaginatedList;


/**
 * @title (#)PaymentDao.java<br>
 * @description 繳費單Dao<br>
 * @author Jimmy Liu<br>
 * @version 1.0.0 2010/11/25
 * @copyright Far Eastern International Bank Copyright (c) 2010<br>
 * @2010/11/18 create by Jimmy Liu<br>
 */
public interface PaymentDao extends HibernateDao<Payment, Long> {

    /**
     * 依uploadfile pk 值整批更新繳費狀態
     * @param paymentStatus
     * @param uploadFile
     * @author Leo Lee
     */
    public void updatePaymentStatusByUploadFilePk(Integer paymentStatus , UploadFile uploadFile);

    /**
     * 取得檔案應繳總金額
     * @param uploadFilePk	上傳檔案檔pk 值
     * @param paymentStatus 繳費狀態
     * @return 總金額
     * @author Leo Lee
     */
    public Long getTotalAmountByUploadFilePk(Long uploadFilePk, Integer paymentStatus);

    /**
     * 取得檔案應該總筆數
     * @param uploadFilePk 上傳檔案檔pk 值
     * @param paymentStatus 繳費狀態
     * @return 總筆數, 若回傳為 0 則查無應繳筆數
     * @author Leo Lee
     */
    public Long getCountItemByUploadFilePk(Long uploadFilePk, Integer paymentStatus);

    /**
     * 依據查詢物件與繳費截止日期起迄查詢繳費單
     * @param payment 查詢條件
     * @param payDueFrom 繳費截止日期起
     * @param payDueTo 繳費截止日期迄
     * @param paginationConfig 換頁條件
     * @return 查詢結果物件
     */
    public PaginatedList<Payment> queryPaginationByPayment(Payment payment, Date payDueFrom, Date payDueTo, PaginatedList<Payment> paginationConfig);
    
    /**
     * 依uploadfile pk 值來刪除繳費資料
     * @param uploadFile
     */
    public void deletePaymentByUploadFile(UploadFile uploadFile);

    /**
     * 依paymentPk 取回單筆 Payment 檔
     * @param payment
     * @return
     */
    public Payment getPaymentByPk(Payment payment);

    /**
     * 依paymentPk 取回單筆 Payment 檔
     * @param payment
     * @return
     */
    public List<Payment> getPaymentByPk(List<Payment> payment);
    
    public PaginatedList<Payment> queryPaginationByPayment(Payment payment,
                    Date payDueFrom, Date payDueTo,
                    PaginatedList<Payment> paginationConfig, String queryType);

    /**
     * 查出此uploadfilepk 所有相關的paymentpk
     * @param uploadFilePk
     * @return
     */
    public List<Long> queryPaymentPkByUploadFilePk(Long uploadFilePk);

    public List<Payment> queryStatus3(Payment payment, PaginatedList<Payment> paginationConfig);
    
    public List<Payment> queryStatus2(Payment payment, PaginatedList<Payment> paginationConfig);
    
    public void updatePaymentStatusAs2(ArrayList<Payment> payment);
    
    public void updatePaymentStatusAs4(ArrayList<Payment> payment);
    
    public void updateWriteOffPaymentStatusAs2(ArrayList<Payment> payment);
    
    public void updateWriteOffPaymentStatusAs5(ArrayList<Payment> payment);

    
    public List<Payment> queryDownloadPayments(Group qryGroup,
                    Date qryPayDueFrom, Date qryPayDueTo, 
                    String qryVirtualAccountFrom, String qryVirtualAccountTo);

    public List<Payment> queryByUploadFiles(
                    UploadFile uploadFile, Integer qryPaymentStatus);

    /**
     * @param formatDefinitionPk
     * @return
     */
    public int countByFormatDefinitionPk(Long formatDefinitionPk);

    /**
     * @param payment 查詢條件
     * @param formatDefinition 收款類別
     * @param payDueFrom 繳費期限起
     * @param payDueTo 繳費期限迄
     * @param writeOffDateFrom 繳費交易日期起
     * @param writeOffDateTo 繳費交易日期迄
     * @param paginationConfig 分頁、排序條件
     * @return
     */
    public PaginatedList<Payment> queryPaginationByPayment(Payment payment, FormatDefinition formatDefinition, Date payDueFrom, Date payDueTo, Date writeOffDateFrom, Date writeOffDateTo, Date txDateFrom, Date txDateTo, PaginatedList<Payment> paginationConfig);
    

    /**
     * 依據查詢物件與繳費截止日期起迄查詢繳費單
     * @param payment 查詢條件
     * @param payDueFrom 繳費截止日期起
     * @param payDueTo 繳費截止日期迄
     * @param paginationConfig 換頁條件
     * @return 查詢結果物件
     */
    public PaginatedList<Payment> queryPaginationByPaymentSql(Payment payment, FormatDefinition formatDefinition, Date payDueFrom, Date payDueTo, Date writeOffDateFrom, Date writeOffDateTo, Date txDateFrom, Date txDateTo, PaginatedList<Payment> paginationConfig);
    

    /**
     * @param virtualAccount
     * @param unPay
     * @return
     */
    public Payment queryPaymentByVirtualAccount(String virtualAccount, boolean unPay);

    /**
     * @param writeOffPayment
     */
    public void updateWriteOffPaymentStatusAs5ForOnLine(WriteOffPayment writeOffPayment);
    //黃郁珊 依中租需求修改
    public List<String> queryPayerIdByUploadFilePk(Long uploadFilePk);
    
    public List<String> queryPaymentStatusByUploadFilePk(Long uploadFilePk);
    
    public int getPaymentByGroup_type(String virtualAccount);

	public List<Payment> queryPayementByPayerId(String payerId,
			Long uploadFilePk);
    //2011.12 by Leo
    public List<Payment> queryPaymentByGroup(Group group, Integer qryDateType, Date qryDateFrom, Date qryDateTo);
    public List<Payment> queryPaymentByParam(Payment payment, String userno, String type);
    
   /**
    * 獲得合併下載的繳費單清單
    * @author Jeff Gu
    * @param payment
    * @param qryPayDueFrom
    * @param qryPayDueTo
    * @param qryVirtualAccountFrom
    * @param qryVirtualAccountTo
    * @return
    */
    public List<Payment> queryDownloadPayments(Payment payment,
            Date qryPayDueFrom, Date qryPayDueTo, 
            String qryVirtualAccountFrom, String qryVirtualAccountTo);

    /**
     * TODO 2012 10/1 JEFF
     * 查詢結果新增筆數與金額統計
     * @author Jeff Gu
     * @param payment 查詢條件
     * @param payDueFrom 繳費截止日期起
     * @param payDueTo 繳費截止日期迄
     * @param paginationConfig 換頁條件
     *
     */
   public List<Map<String,Object>> querySumByPaymentSql(Payment payment, FormatDefinition formatDefinition, Date payDueFrom, Date payDueTo, Date writeOffDateFrom, Date writeOffDateTo, Date txDateFrom, Date txDateTo);
   
   /**
    * TODO 2012 10/1 JEFF
    * 逾期查詢
    * 依據查詢物件與繳費截止日期起迄查詢繳費單
    * @param payment 查詢條件
    * @param payDueFrom 繳費截止日期起
    * @param payDueTo 繳費截止日期迄
    * @param paginationConfig 換頁條件
    * @return 查詢結果物件
    */
   public PaginatedList<Payment> queryDelayPaymentPaginationBySql(Payment payment, FormatDefinition formatDefinition, Date payDueFrom, Date payDueTo, Date writeOffDateFrom, Date writeOffDateTo, Date txDateFrom, Date txDateTo, PaginatedList<Payment> paginationConfig,boolean isSchool, int delayCount);

   
   /**
    * TODO 2012 10/1 JEFF
    * 逾期查詢
    * 查詢結果新增筆數與金額統計
    * @author Jeff Gu
    * @param payment 查詢條件
    * @param payDueFrom 繳費截止日期起
    * @param payDueTo 繳費截止日期迄
    * @param paginationConfig 換頁條件
    *
    */
  public List<Map<String,Object>> queryDelaySumByPaymentSql(Payment payment, FormatDefinition formatDefinition, Date payDueFrom, Date payDueTo, Date writeOffDateFrom, Date writeOffDateTo, Date txDateFrom, Date txDateTo,boolean isSchool, int delayCount);

    
}
